<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class User_favor extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->load->model('user_favor_m');
        $this->load->helper('date');
    }
    
    function insert(){
        $arr=array(
                    'userid'=>1,
                    'subjectid'=>1,
                    'time'=>date("Y-m-d")
            );
        $this->user_favor_m->insert($arr);
    }
    
    function delete(){
        $userid=$this->input->post('userid');
        $subjectid=$this->input->post('subjectid');
        $this->user_favor_m->delete($userid,$subjectid);
    }
    
    function getlist($userid){
        $subjects=$this->user_favor_m->select($userid);
        header("Content-Type:text/html;charset=utf8");
        if($subjects){
            foreach ($subjects as $s){
                foreach($s as $key=>$val){
                    $s->$key=  urlencode($val);
                }
            }
            $result=array('code'=>'success','msg'=>'','data'=>json_encode($subjects));
            echo urldecode(json_encode($result));
        }
    }
}
